﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace MyServer.Todo.Infrastructure.Migrations
{
    public partial class init : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "todo_group",
                columns: table => new
                {
                    id = table.Column<string>(type: "character varying(36)", maxLength: 36, nullable: false),
                    name = table.Column<string>(type: "text", nullable: true),
                    user_id = table.Column<string>(type: "text", nullable: true),
                    creation_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    todo_type = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_todo_group", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "todo",
                columns: table => new
                {
                    id = table.Column<string>(type: "character varying(36)", maxLength: 36, nullable: false),
                    name = table.Column<string>(type: "text", nullable: true),
                    notes = table.Column<string>(type: "text", nullable: true),
                    todo_status = table.Column<int>(type: "integer", nullable: false),
                    creation_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    todo_group_id = table.Column<string>(type: "character varying(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_todo", x => x.id);
                    table.ForeignKey(
                        name: "FK_todo_todo_group_todo_group_id",
                        column: x => x.todo_group_id,
                        principalTable: "todo_group",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "todo_group_settings",
                columns: table => new
                {
                    id = table.Column<string>(type: "character varying(36)", maxLength: 36, nullable: false),
                    is_hidden = table.Column<bool>(type: "boolean", nullable: false),
                    theme = table.Column<int>(type: "integer", nullable: false),
                    todo_group_id = table.Column<string>(type: "character varying(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_todo_group_settings", x => x.id);
                    table.ForeignKey(
                        name: "FK_todo_group_settings_todo_group_todo_group_id",
                        column: x => x.todo_group_id,
                        principalTable: "todo_group",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "todo_settings",
                columns: table => new
                {
                    id = table.Column<string>(type: "character varying(36)", maxLength: 36, nullable: false),
                    expiration_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    category = table.Column<int>(type: "integer", nullable: false),
                    is_important = table.Column<bool>(type: "boolean", nullable: false),
                    is_myday = table.Column<bool>(type: "boolean", nullable: false),
                    todo_id = table.Column<string>(type: "character varying(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_todo_settings", x => x.id);
                    table.ForeignKey(
                        name: "FK_todo_settings_todo_todo_id",
                        column: x => x.todo_id,
                        principalTable: "todo",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_todo_todo_group_id",
                table: "todo",
                column: "todo_group_id");

            migrationBuilder.CreateIndex(
                name: "IX_todo_group_settings_todo_group_id",
                table: "todo_group_settings",
                column: "todo_group_id",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_todo_settings_todo_id",
                table: "todo_settings",
                column: "todo_id",
                unique: true);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "todo_group_settings");

            migrationBuilder.DropTable(
                name: "todo_settings");

            migrationBuilder.DropTable(
                name: "todo");

            migrationBuilder.DropTable(
                name: "todo_group");
        }
    }
}
